
public class PrimaryExpr {
	String nm;
	String bl;
	String st;
	String id;
	CallExpr ce;
	String lp;
	Expression exp;
	String rp;
	int lineNum;
	int charPos;
	boolean fromIf;
	
	public PrimaryExpr(String nm, String bl, String st, String id, CallExpr ce, String lp, Expression exp, String rp, int line, int charP){
		this.nm = nm;
		this.bl = bl;
		this.st = st;
		this.id = id;
		this.ce = ce;
		this.lp = lp;
		this.exp = exp;
		this.rp = rp;
		this.lineNum = line;
		this.charPos = charP;
	}
	public String toString(){
		String ret = "";

		String s = "";
		if (nm != null)
			s+=nm;
		if (bl != null)
			s+=bl;
		if (st != null)
			s+=st;
		if (id != null)
			s+=id;
		if (ce != null) {
			s +=  ce.toString();
		}
		if (exp != null) {
			s +=  exp.toString();
		}
		
		return ret+s;
	}
	public void check(Type t) throws SemanticException {
		SymbolTable table = SymbolTable.getInstance();
		if (nm != null){
			if(t!=null && t.type == "int"){
				if(nm.contains(".")){
					throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nTypes mismatch, input should be of type 'int'.\nIn: " + Parser.getLineOfCode(this.lineNum));
				}
			}else if(t!=null && t.type == "float"){
					if(!nm.contains(".")){
						throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nTypes mismatch, input should be of type 'float'.\nIn: " + Parser.getLineOfCode(this.lineNum));
					}
				}else{
					if(t!=null)
						throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nTypes mismatch.\nIn: " + Parser.getLineOfCode(this.lineNum));
				}
		}
		if (bl != null){
			if(t!=null && t.type != "boolean"){
				throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nTypes mismatch, input should be of type 'boolean'.\nIn: " + Parser.getLineOfCode(this.lineNum));
			}
		}
			
		if (st != null){
			if(t!=null && t.type != "String"){
				throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nTypes mismatch, input should be of type 'String'.\nIn: " + Parser.getLineOfCode(this.lineNum));
			}
		}
		
		//System.out.println("PrimaryExpr " + nm + " " + bl + " " + st + " " + id + " " + lp + " " + rp);
		//System.out.println("tab eh tab ?");
		if (ce != null) {
			//System.out.println("PrimaryExpr 1");
			ce.check(t);
		}
		if (exp != null) {
			//System.out.println("PrimaryExpr 2");	
			exp.fromIf= this.fromIf;
			exp.check(t);
		}
		if( id != null){
			if(!table.contains(id)){
				throw new SemanticException("Semantic Error at line " + this.lineNum + " char " + this.charPos + ":\nThe identifier " + id + " was not declared.\nIn: " + Parser.getLineOfCode(this.lineNum));
			}
		}
	}
}
